package com.google.sydym6.view.adapters;

import java.util.List;

import com.google.sydym6.R;
import com.google.sydym6.logic.database.data.IRadioData;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class RadioListAdapter extends BaseAdapter {
	
	private Context context;
	private LayoutInflater inflater;
	private List<IRadioData> stations;
	private int idItem;

	public RadioListAdapter(Context context, int idItem, List<IRadioData> stations) {
		this.context = context;
		this.idItem = idItem;
		this.stations = stations;
		
		inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		return stations.size();
	}

	@Override
	public Object getItem(int position) {
		return stations.get(position);
	}

	@Override
	public long getItemId(int position) {
		return stations.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if (view == null) {
			view = inflater.inflate(idItem, parent, false);
		}
		
		IRadioData data = getRadioData(position);
		((TextView) view.findViewById(R.id.tvText)).setText(data.getTitle());
		
		return view;
	}

	private IRadioData getRadioData(int position) {
		return ((IRadioData) getItem(position));
	}
}
